<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'frontend.main.class.php');
$feObj = new FrontendMainBase();

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/product/product.class.php');
$pObj = new ProductBase();
$pObj->format = true;

//
$item = $pObj->getItem($request_link_class, 'link');
if( $item['id'] > 0 ) {
	//category
	include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/product/product.category.class.php');
	$pcObj = new ProductCategoryBase();
	$pcObj->format = true;
	$category = $pcObj->getCategory($item['cid']);
	$feObj->addContent('category', $category);
	
	//nav
	$pObj->setQueryLimitLength(12);
	$items = $pObj->getItems(array('cid' => $item['cid']), 0, true);
	/*
	$count = count($items);
	if( $count < 12 ) {
		$pObj->setQueryLimitLength(12 - $count);
		$items_ = $pObj->getItems('', 0, true);
		foreach($items_ as $item_) {
			$items[] = $item_;
		}
	}
	*/
	$feObj->addContent('nav_items', $items);
	
	//images
	$images = $pObj->getImages($item['id']);
	$feObj->addContent('images', $images);
	
	//videos
	$videos = $pObj->getVideos($item['id']);
	$feObj->addContent('videos', $videos);
	$feObj->addContent('video', $videos[0]['item']);
	
	//description
	include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/product/product.description.class.php');
	$mObj = new ProductDescriptionBase();
	$mObj->format = true;
	
	//
	if( !in_array($request_link_subclass, array('features', 'specifications', 'applications')) ) {
		$request_link_subclass = 'features';
	}
	
	//features
	if( $request_link_subclass == 'features' ) {
		$mObj->setTargetType($item['id'], 1);
		$item['features'] = $mObj->getValue();
		
		$mainpart = $request_link_subclass;
	}
	
	//specifications
	if( $request_link_subclass == 'specifications' ) {
		$mObj->setTargetType($item['id'], 2);
		$item['specifications'] = $mObj->getValue();
		
		$mainpart = $request_link_subclass;
	}
	
	//applications
	if( $request_link_subclass == 'applications' ) {
		$mObj->setTargetType($item['id'], 3);
		$item['applications'] = $mObj->getValue();
		
		$mainpart = $request_link_subclass;
	}
} else {
	$mainpart = 'noproduct';
}

//
$feObj->addCssFile('p.css');
//$feObj->addJsFileExt('http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js');
$feObj->addJsFile('jquery/jquery-1.4.2.min.js');
//
$feObj->addTitle($item['name'] . ' - ' . $item['model'], ' - ');
$feObj->addContent('mainpart', $mainpart);
$feObj->addContent('item', $item);
echo $feObj->display('pagelayout/pagelayout_main_product.tpl');
//
?>